Skip to content

Conversation

yashksaini-coder
Copy link
Contributor

What was wrong?

My previous PR #811 lacked the code changes on, multiple examples and core modules that were using wildcard addresses (0.0.0.0) for binding, which could expose services on all network interfaces and create security vulnerabilities.

How was it fixed?

I updated all the modules files and refactored to replace all wildcard bind addresses (0.0.0.0) with secure loopback addresses (127.0.0.1) across the entire codebase:

Examples Directory (17 files updated)

  • Core examples: ping.py, chat.py, bootstrap.py, mDNS.py, pubsub.py, random_walk.py, identify.py, identify_push_listener_dialer.py
  • Documentation examples: All 8 files in examples/doc-examples/ directory
  • Advanced examples: network_discover.py (updated fallback functions)

Core Library Updates

  • libp2p/utils/address_validation.py: Updated fallback addresses from 0.0.0.0 to 127.0.0.1

Documentation Updates (5 files)

  • Updated all .rst files in docs/examples.*.rst to reflect new secure addresses

Testing & Validation

  • tests/utils/test_default_bind_address.py: Comprehensive tests for secure address selection
  • tests/examples/test_examples_bind_address.py: Validation that all examples use secure addresses

Release Notes

  • newsfragments/885.feature.rst: Security enhancement notification

To-Do

  • Clean up commit history
  • Add or update documentation related to these changes
  • Add entry to the release notes

cc: @acul71 @seetadev @pacrob

@seetadev
Copy link
Contributor

seetadev commented Sep 2, 2025

@yashksaini-coder : Great contribution, Yash. Appreciate your efforts. This PR is coming along nicely.

Looking forward to detailed review by @acul71 on this PR.

@acul71
Copy link
Contributor

acul71 commented Sep 2, 2025

@yashksaini-coder

  1. Fix the get_available_interfaces so that it don't return duplicate addresses
  2. Take a look at all the examples in /examples and when you see something like that:
(venv) luca@r17:~/PNL_Launchpad_Curriculum/Libp2p/py-libp2p$ identify-demo 
First host listening (using raw protobuf format). Run this from another console:

identify-demo --raw-format -d /ip4/127.0.0.1/tcp/37511/p2p/QmVUKiaLFMt9AVALFTPCRycCM2FArzugTLScVKaeeoCyxc

or like that

(venv) luca@r17:~/PNL_Launchpad_Curriculum/Libp2p/py-libp2p$ ping-demo 
Run this from the same folder in another console:

ping-demo -d /ip4/0.0.0.0/tcp/42547/p2p/QmRShbR5CqVSkF4zWKCUhx7BwU9MonXV5LNxFDT1CborEk

Waiting for incoming connection...

it should be instead similar to this:

(venv) luca@r17:~/PNL_Launchpad_Curriculum/Libp2p/py-libp2p$ echo-demo 
Listener ready, listening on:

/ip4/192.168.1.17/tcp/43857/p2p/16Uiu2HAmJcvmEow2iaFDEexsN2HMqzX8DcwxhDct87YYnoQNhv7m
/ip4/10.156.233.51/tcp/43857/p2p/16Uiu2HAmJcvmEow2iaFDEexsN2HMqzX8DcwxhDct87YYnoQNhv7m
/ip4/127.0.0.1/tcp/43857/p2p/16Uiu2HAmJcvmEow2iaFDEexsN2HMqzX8DcwxhDct87YYnoQNhv7m

Run this from the same folder in another console:

echo-demo -d /ip4/192.168.1.17/tcp/43857/p2p/16Uiu2HAmJcvmEow2iaFDEexsN2HMqzX8DcwxhDct87YYnoQNhv7m

Waiting for incoming connections...

So that it shows all available interfaces and a default command for the client (Run this form the same folder in ......)

  1. Test manually all the tests (not all options) to see that they work with your mods (there are some tests but don't cover a real test)
    This way you also become familiar with various core protocols in py-libp2p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants